package com.app.service.impl;

import com.app.mapper.ClickStatisticsMapper;
import com.app.model.ClickStatisticsModel;
import com.app.service.ClickStatisticsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary
public class ClickStatisticsServiceImpl implements ClickStatisticsService {
    @Autowired
    ClickStatisticsMapper clickStatisticsMapper;


    @Override
    public List<ClickStatisticsModel> getCountList() {
        QueryWrapper<ClickStatisticsModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("SUBSTRING(crt_time,6,6) as countKey,count(LEFT(crt_time,10)) as countValue");
        queryWrapper.apply(" DATE_SUB(CURDATE(), INTERVAL 15 DAY) <= DATE( crt_time ) ");
        queryWrapper.groupBy("LEFT(crt_time,10)");
        queryWrapper.orderByAsc("LEFT(crt_time,10)");
        List<ClickStatisticsModel> list = clickStatisticsMapper.selectList(queryWrapper);

        return list;
    }
}
